/*
Copyright 2010 Sieric
http://sieric.ca

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package vanilla;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComponent;

@SuppressWarnings("serial")
public class Section_Choose extends JComponent implements Section, ActionListener {
	private Section theOne = null;
	private JComponent theComp = null;
	private int bigHeight;
	
	public Section_Choose() {
		// Find the biggest height
		bigHeight = Math.max(20, (new Section_Local()).getBigHeight());
		bigHeight = Math.max(bigHeight, (new Section_FTP()).getBigHeight());
		
		// Display the buttons
		JButton tmp;
		
		tmp = new JButton("Local");
		tmp.addActionListener(this);
		tmp.setBounds(1, 1, 80, 20);
		add(tmp);
		
		tmp = new JButton("FTP");
		tmp.addActionListener(this);
		tmp.setBounds(81, 1, 80, 20);
		add(tmp);
		
	}
	
	public int getBigHeight() {
		return bigHeight;
	}

	public String getConfig() {
		if (theOne != null) return theOne.getConfig(); 
			
		return null;
	}

	public void actionPerformed(ActionEvent arg0) {
		if (arg0.getActionCommand().compareTo("Local") == 0) {
			Section_Local tmp = new Section_Local();
			theOne = tmp;
			theComp = tmp;
		}
		
		if (arg0.getActionCommand().compareTo("FTP") == 0) {
			Section_FTP tmp = new Section_FTP();
			theOne = tmp;
			theComp = tmp;
		}
		
		Refresh();
	}
	
	public void Refresh() {
		removeAll();
		theComp.setBounds(1, 1, 500, bigHeight);
		add(theComp);
		repaint();
	}

}
